package com.ftg.product.shoumai.controller;

import com.ftg.product.shoumai.pojo.Order;
import com.ftg.product.shoumai.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zwl
 * Create on 2019/8/23 15:56
 * function
 */
@RestController
@CrossOrigin
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderservice;
    @PostMapping("/show")
    public Map<String,Object> showall(@RequestBody Order PageH){
        //开始分页Admin>集合
        PageHelper.startPage(PageH.getPage(),PageH.getLimit());
        //用List< 去存service层调用的方法
        List<Order> list = orderservice.showall(PageH);
        //包装查询后的结果
        PageInfo<Order> page = new PageInfo<>(list);
        //实例化map结果集
        Map<String,Object> map = new HashMap<>();
        //将list中的数据放入map中
        map.put("data",list);
        //code码 为0
        map.put("code","0");
        //成功信息为success
        map.put("msg","success");
        //将总数据条数放入map中
        map.put("count",page.getTotal());
        //返回map
        return map;
    }
    @PostMapping("/insert")
    public int insert(@RequestBody Order order){
        return orderservice.insert(order);
    }
}
